Passed
Push — master ( 325ff9...2f33bc )
by Johan
02:54
created

( ➔ ... ➔ ???   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 1
rs 10
1
/*jslint node: true, nomen: true, regexp: true, plusplus: true */
2
(function () {
3
4
    'use strict';
0 ignored issues
show
Unused Code introduced by
The expression "'use strict'" has no effects. Consider removing it.
Loading history...
5
6
    const   chai            = require("chai"),
7
            should          = chai.should(),
8
            expect          = chai.expect;
9
10
    const   Blockfolio      = require("../index");
11
12
    const   FAKE_TOKEN      = "1915f3d2ef313e86";
13
14
    describe("Blockfolio API", function() {
15
        describe("General", function () {
16
            it("Get the API version", function (done) {
17
                Blockfolio.getVersion((err, version) => {
18
                    if (err) { return done(err); }
19
                    should.exist(version);
20
                    expect(version).to.be.a("number");
21
                    return done();
22
                });
23
            });
24
            it("Get the system status of the API", function (done) {
25
                Blockfolio.getStatus((err, statusMsg) => {
26
                    if (err) { return done(err); }
27
                    should.exist(statusMsg);
28
                    expect(statusMsg).to.be.a("string");
29
                    return done();
30
                });
31
            });
32
            it("Get the announcements from SIGNAL", function (done) {
33
                Blockfolio.getAnnouncements((err, announcements) => {
34
                    if (err) { return done(err); }
35
                    should.exist(announcements);
36
                    expect(announcements).to.be.an("array");
37
                    return done();
38
                });
39
            });
40
            it("should fail at registering an already activated DEVICE_TOKEN", function (done) {
41
                Blockfolio._register(FAKE_TOKEN, (err, response) => {
42
                    should.exist(err.message);
43
                    should.not.exist(response);
44
                    return done();
45
                });
46
            });
47
        });
48
        describe("Module Instanciation", function () {
49
            it("a protected method called without it should return an error", function (done) {
50
                Blockfolio.getPositions("BTC/USD", (err, positions) => {
51
                    should.exist(err.message);
52
                    expect(err.message).to.equal("A valid CLIENT_TOKEN should be provided! (Have you called Blockfolio.init()?)");
53
                    should.not.exist(positions);
54
                    return done();
55
                });
56
            });
57
            it("should fail to initialize with a disposable token", function (done) {
58
                Blockfolio.init("40f027b891222cdf7fe7d7390a29e4bb5c79ea7adbab660c855b2d6c603de2d710c10aebcc4ee76c6da4402457cbfd50", (err) => {
59
                    should.exist(err.message);
60
                    return done();
61
                });
62
            });
63
            // Expand timeout for initialization
64
            this.timeout(5000);
65
            it("should be ok with a working token", function (done) {
66
                try {
67
                    Blockfolio.init(FAKE_TOKEN, (err) => {
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
68
                        if (err) { return done(err); }
69
70
                        return done();
71
                    });
72
                } catch (e) {
73
                    return done(e);
74
                }
75
            });
76
        });
77
        describe("Tools", function () {
78
            it("should return a random token", function (done) {
79
                const generatedToken = Blockfolio.utils.generateClientToken();
80
                expect(generatedToken).to.be.a("string");
81
                return done();
82
            });
83
            it("should convert properly XRP/BTC to a pair struct", function (done) {
84
                const pair = Blockfolio.utils.parseToken("XRP/BTC");
85
                expect(pair).to.be.deep.equal({base: "BTC", token: "XRP"});
86
                return done();
87
            });
88
            it("should convert properly BTC/USD to a pair struct", function (done) {
89
                const pair = Blockfolio.utils.parseToken("BTC/USD");
90
                expect(pair).to.be.deep.equal({base: "USD", token: "BTC"});
91
                return done();
92
            });
93
            it("should convert properly AEON to a pair struct", function (done) {
94
                const pair = Blockfolio.utils.parseToken("AEON");
95
                expect(pair).to.be.deep.equal({base: "BTC", token: "AEON"});
96
                return done();
97
            });
98
            it("should convert properly BTC-LTC to a pair struct", function (done) {
99
                const pair = Blockfolio.utils.parseToken("BTC-LTC");
100
                expect(pair).to.be.deep.equal({base: "BTC", token: "LTC"});
101
                return done();
102
            });
103
            it("should convert properly BTC-DASH to a pair struct", function (done) {
104
                const pair = Blockfolio.utils.parseToken("BTC-DASH");
105
                expect(pair).to.be.deep.equal({base: "BTC", token: "DASH"});
106
                return done();
107
            });
108
            it("should convert properly BTC-BCH to a pair struct", function (done) {
109
                const pair = Blockfolio.utils.parseToken("BTC-BCH");
110
                expect(pair).to.be.deep.equal({base: "BTC", token: "BCH"});
111
                return done();
112
            });
113
        });
114
        describe("Endpoints", function () {
115
            // Expand timeout for network & API lentency
116
            this.timeout(10000);
117
            it("Get the currencies list", function (done) {
118
                Blockfolio.getCurrencies((err, currencies) => {
119
                    if (err) { return done(err); }
120
                    should.exist(currencies);
121
                    expect(currencies).to.be.an("array");
122
                    return done();
123
                });
124
            });
125
            it("Get the coins list", function (done) {
126
                Blockfolio.getCoinsList((err, coins) => {
127
                    if (err) { return done(err); }
128
                    should.exist(coins);
129
                    expect(coins).to.be.an("array");
130
                    return done();
131
                });
132
            });
133
            it("Get a Disposable Device Token", function (done) {
134
                Blockfolio.getDisposableDeviceToken(token => {
135
                   should.exist(token);
136
                   return done();
137
                });
138
            });
139
            it("Get market details for an AEON/BTC", function (done) {
140
                Blockfolio.getMarketDetails("AEON/BTC", "bittrex", (err, details) => {
141
                    if (err) { return done(err); }
142
143
                    should.exist(details.ask);
144
                    expect(details.ask).to.be.a("string");
145
                    return done();
146
                });
147
            });
148
            it("Get available exchanges for this token", function (done) {
149
                Blockfolio.getExchanges("AEON/BTC", (err, exchanges) => {
150
                    if (err) { return done(err); }
151
152
                    expect(exchanges).to.be.an("array");
153
                    return done();
154
                });
155
            });
156
            it("Get available exchanges for an incorrect token", function (done) {
157
                Blockfolio.getExchanges("ZSKJD/BTC", (err, exchanges) => {
158
                    should.exist(err.message);
159
                    expect(err.message).to.equal("ZSKJD is not an available token on Blockfolio!");
160
                    should.not.exist(exchanges);
161
                    return done();
162
                });
163
            });
164
            it("Add a token pair to watch from Bittrex", function (done) {
165
                Blockfolio.watchCoin("AEON/BTC", "bittrex", (err, res) => {
166
                    if (err) { return done(err); }
167
168
                    expect(res).to.equal("success");
169
                    return done();
170
                });
171
            });
172
            it("Get the last price of an incorrect token on this exchange", function (done) {
173
                Blockfolio.getPrice("EAZRREZREZ/BTC", "bittrex", (err, rPrice) => {
174
                    should.exist(err.message);
175
                    expect(err.message).to.equal("EAZRREZREZ is not an available token on Blockfolio!");
176
                    should.not.exist(rPrice);
177
                    return done();
178
                });
179
            });
180
181
182
            it("... and with a valid token, but an incorrect base", function (done) {
183
                Blockfolio.getPrice("BTC/DSQFSDFDSF", "bittrex", (err, nPrice) => {
0 ignored issues
show
Unused Code introduced by
The parameter nPrice is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
184
                    should.exist(err.message);
185
                    expect(err.message).to.equal("BTC is not an available in DSQFSDFDSF on Blockfolio!");
186
                    return done();
187
                });
188
            });
189
190
191
            it("Get the last price of AEON on this exchange", function (done) {
192
                Blockfolio.getPrice("AEON/BTC", "bittrex", (err, cPrice) => {
193
                    if (err) { return done(err); }
194
195
                    expect(cPrice).to.be.a("number");
196
                    return done();
197
                });
198
            });
199
            it("Add a BTC position on this pair", function (done) {
200
                Blockfolio.addPosition(true, "AEON/BTC", "bittrex", 0.00018, 200, "AEON FTW", (err, res) => {
201
                    if (err) { return done(err); }
202
203
                    expect(res).to.equal("success");
204
                    return done();
205
                });
206
            });
207
            it("Get the summary for current position", function (done) {
208
                Blockfolio.getHoldings("AEON/BTC", (err, summary) => {
209
                    if (err) { return done(err); }
210
211
                    should.exist(summary.holdingValueString);
212
                    expect(summary.holdingValueString).to.be.a("string");
213
                    return done();
214
                });
215
            });
216
            it("Get orders details for this position", function (done) {
217
                Blockfolio.getPositions("AEON/BTC", (err, positions) => {
218
                    if (err) { return done(err); }
219
220
                    should.exist(positions);
221
                    expect(positions).to.be.an("array");
222
                    return done();
223
                });
224
            });
225
            it("And then remove the coin from portfolio", function (done) {
226
                Blockfolio.removeCoin("AEON/BTC", (err, res) => {
227
                    if (err) { return done(err); }
228
229
                    expect(res).to.equal("success");
230
                    return done();
231
                });
232
            });
233
            it("Get actual positions", function (done) {
234
                Blockfolio.getPositions((err, positions) => {
235
                    if (err) { return done(err); }
236
237
                    should.exist(positions);
238
                    expect(positions).to.be.an("array");
239
                    return done();
240
                });
241
            });
242
        });
243
    });
244
245
})();